<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example_3.html</title>
</head>
<body>
    <!-- 
        题目3: 实现数组的去重, 传入需要去重的纯数字数组,将数组去重,返回数组元素不重复的数组
                函数名：noRepeatArray
                参数：需要去重的纯数字数组
                返回值：去重后的数组
                例如：noRepeatArray([3,3,1,5,1,2]) 返回 [3, 1, 5, 2]
     -->
     第三题:<input type="text" placeholder="3,3,1,5,1,2">
     <button>点击验证</button>
     <input type="text">
</body>
</html>
<script>
    let oInput = document.getElementsByTagName("input");
    let oBtn = document.getElementsByTagName("button");
    // console.log(oInput, oBtn)

    function noRepeatArray(str) {
        let arr = str.split(",");
        let newArr =[]

        for(let i = 0; i < arr.length; i++) {
            if(newArr.indexOf(arr[i]) == -1) {
                newArr.push(arr[i]);
            }
        }
        return newArr;
        
    }

    oBtn[0].onclick = function() {
        oInput[1].value = noRepeatArray(oInput[0].value);

    }
</script>
